//
//  RecommentCycleViewCell.swift
//  SwiftDemo
//
//  Created by liguoqing on 2022/6/28.
//  Copyright © 2022 guoqing.li. All rights reserved.
//

import UIKit
import Kingfisher

class RecommentCycleViewCell : UICollectionViewCell {
    
    private lazy var imgView: UIImageView = {
        let imgView = UIImageView()
        return imgView
    }()
    
   private lazy var backView: UIView = {
        let backView = UIView()
        backView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
        return backView
    }()
    
    lazy var titleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = .white;
        titleLabel.font = UIFont.systemFont(ofSize: 14)
        return titleLabel
    }()
    
    var cycleModel : CycleModel? {
        didSet{
            guard let cycleModel = cycleModel else {
                return
            }
            titleLabel.text = cycleModel.title
            
            let iconUrl = URL(string: cycleModel.pic_url )!
            let resource = ImageResource(downloadURL: iconUrl as URL)
            imgView.kf.setImage(with: resource, placeholder:  UIImage(named: "Img_default"))
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension RecommentCycleViewCell {
    
    private func setupUI() {
        contentView.addSubview(imgView)
        contentView.addSubview(backView)
        contentView.addSubview(titleLabel)
        imgView.snp.makeConstraints { make in
            make.edges.equalTo(0)
        }
        backView.snp.makeConstraints { make in
            make.leading.bottom.trailing.equalTo(0)
            make.height.equalTo(30)
        }
        titleLabel.snp.makeConstraints { make in
            make.leading.equalTo(0)
            make.top.equalTo(10);
            make.width.equalTo(kScreenW-100)
            make.bottom.equalTo(-10)
        }
    }
}
